# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html
import scrapy

from components.custom_item import UpdateCustomItem
import json


class NetSeriousDishonestyItem(UpdateCustomItem):
    name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    business_status = scrapy.Field()
    tag = scrapy.Field()
    court_of_execution = scrapy.Field()
    bureau = scrapy.Field()
    docunumber = scrapy.Field()
    filing_time = scrapy.Field()
    reference = scrapy.Field()
    unit = scrapy.Field()
    obligation = scrapy.Field()
    performance_status = scrapy.Field()
    dpecific_situation = scrapy.Field()
    release_time = scrapy.Field()
    fulfilled_portion = scrapy.Field()
    unfulfilled_portion = scrapy.Field()
    data_sources = scrapy.Field()
    keyword = scrapy.Field()

    def pre_to_db(self):
        self.docunumber = json.dumps(self.docunumber, ensure_ascii=False)
        self.obligation = json.dumps(self.obligation, ensure_ascii=False)
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"


class NetBusinessAnomalyItem(UpdateCustomItem):
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    legal_person = scrapy.Field()
    pripid = scrapy.Field()
    regno = scrapy.Field()
    specausename = scrapy.Field()
    abntime = scrapy.Field()
    decorgname = scrapy.Field()
    data_sources = scrapy.Field()
    keyword = scrapy.Field()

    def pre_to_db(self):
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"


class NetAdministrativePenaltyItem(UpdateCustomItem):
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    cf_wsh = scrapy.Field()
    cf_cflb = scrapy.Field()
    cf_jdrq = scrapy.Field()
    cf_nr = scrapy.Field()
    cf_nr_fk = scrapy.Field()
    cf_nr_wfff = scrapy.Field()
    cf_nr_zkdx = scrapy.Field()
    cf_wfxw = scrapy.Field()
    cf_sy = scrapy.Field()
    cf_yj = scrapy.Field()
    cf_cfjg = scrapy.Field()
    cf_cfjgdm = scrapy.Field()
    cf_sjlydm = scrapy.Field()
    data_sources = scrapy.Field()
    keyword = scrapy.Field()

    def pre_to_db(self):
        self.cf_nr = json.dumps(self.cf_nr, ensure_ascii=False)
        self.cf_wfxw = json.dumps(self.cf_wfxw, ensure_ascii=False)
        self.cf_sy = json.dumps(self.cf_sy, ensure_ascii=False)
        self.cf_yj = json.dumps(self.cf_yj, ensure_ascii=False)
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"


class NetAdministrativeLicenseItem(UpdateCustomItem):
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    xk_wsh = scrapy.Field()
    xk_wsmc = scrapy.Field()
    xk_zsmc = scrapy.Field()
    xk_lx = scrapy.Field()
    xk_bh = scrapy.Field()
    xk_jdrq = scrapy.Field()
    xk_yxqq = scrapy.Field()
    xk_yxqz = scrapy.Field()
    xk_nr = scrapy.Field()
    xk_jg = scrapy.Field()
    xk_xydm = scrapy.Field()
    xk_sjly = scrapy.Field()
    xk_sjlydm = scrapy.Field()

    def pre_to_db(self):
        self.xk_nr = json.dumps(self.xk_nr, ensure_ascii=False)
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"


class NetSeriousDishonestyNameListItem(UpdateCustomItem):
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    bureau = scrapy.Field()
    legal_person = scrapy.Field()
    cf_wsh = scrapy.Field()
    cf_ss = scrapy.Field()
    cf_yj = scrapy.Field()
    cf_nr = scrapy.Field()
    cf_jdrq = scrapy.Field()
    sx_wsh = scrapy.Field()
    recognition_basis = scrapy.Field()
    accreditation_authority = scrapy.Field()
    sx_jdrq = scrapy.Field()
    publicity_period = scrapy.Field()
    current_operating_status = scrapy.Field()
    notes = scrapy.Field()
    data_sources = scrapy.Field()
    keyword = scrapy.Field()

    def pre_to_db(self):
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"


class NetSeriousDishonestySafetyNameListItem(UpdateCustomItem):
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    address = scrapy.Field()
    person_name = scrapy.Field()
    id_cards = scrapy.Field()
    manger_date = scrapy.Field()
    department = scrapy.Field()
    data_sources = scrapy.Field()
    keyword = scrapy.Field()

    def pre_to_db(self):
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"


class NetSeriousDishonestyCfcgNameListItem(UpdateCustomItem):
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    address = scrapy.Field()
    cf_nr = scrapy.Field()
    cf_yj = scrapy.Field()
    cf_jg = scrapy.Field()
    cf_jdrq = scrapy.Field()
    department = scrapy.Field()
    end_date = scrapy.Field()
    data_sources = scrapy.Field()
    keyword = scrapy.Field()

    def pre_to_db(self):
        self.taxpayer_id = self.taxpayer_id or "000000000000000000"
